<?php
namespace app\index\model;
use think\Db;
use think\Model;

class Extra extends Model{
    /***
     * 获取是否存在这个孔号
     * @param $sracknumber
     * @return mixed
     */
    public  function MgetabandonBySracknumber($sracknumber){
        //先查询
        return $res = Db::table('s_rack')->where('sracknumber',$sracknumber)->find();
    }
    public function MabandonBySracknumber($sracknumber){
        //开始删除
        $res= Db::execute("update s_rackdetail set state = 0 where sracknumber in(
select sracknumber from s_rack where sracknumber = :sracknumber)",['sracknumber'=>$sracknumber]);

        $da= Db::execute("update s_rack set usednum = 0 where sracknumber = :sracknumber",['sracknumber'=>$sracknumber]);

        if($res && $da){
            return true;
        }
        return false;
    }
    //批量删除 孔号 下面
    public function MabandonByUsednum($usednum){
        //开始删除 --先把没有还原的空位直接还原掉
        $res= Db::execute("UPDATE dbo.s_rackdetail SET state = 0 WHERE sracknumber IN (SELECT sracknumber FROM  s_rack WHERE usednum<:usednum AND usednum>0) AND state<>0 ",['usednum'=>$usednum]);

        //--然后在把记录的总数也还原掉
        $da= Db::execute("UPDATE s_rack SET usednum=0 WHERE usednum<:usednum AND usednum>0",['usednum'=>$usednum]);
        if($res && $da){
            return true;
        }
        return false;
    }

   /***
    *  批量修改 检验目的对照
    */
    public function MJymdDyAlter($oldjymddm_zx,$newjymddm_zx,$newjymdmc_zx){
        $res = Db::execute("update t_lis_jymd_dy set jymddm_zx = :newjymddm_zx, jymdmc_zx = :newjymdmc_zx
        WHERE jymddm_zx  = :oldjymddm_zx",['newjymddm_zx'=>$newjymddm_zx,'newjymdmc_zx'=>$newjymdmc_zx, 'oldjymddm_zx'=>$oldjymddm_zx]);
        if($res){
            return true;
        }
        return false;
    }
}